package com.e.leandemo.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.e.leandemo.R;
import com.e.leandemo.model.Animal;

import java.util.LinkedList;

public class AnimalAdapter extends BaseAdapter {
    private LinkedList<Animal> data;
    private Context context;

    public AnimalAdapter(LinkedList<Animal> data, Context context) {
        this.data = data;
        this.context =context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.animal_list_layout, parent, false);
        }

        TextView nameText=(TextView)convertView.findViewById(R.id.animal_name);
        TextView sayText=(TextView)convertView.findViewById(R.id.animal_say);
        nameText.setText(data.get(position).getName());
        sayText.setText(data.get(position).getSpeak());

        return convertView;
    }
}
